﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class GetATMMassageList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            GetATMMassageListOutParam result = new GetATMMassageListOutParam();
            GetATMMassageListInParam param = new GetATMMassageListInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as GetATMMassageListInParam;

                if (string.IsNullOrEmpty(param.type))
                {
                    result.code = "0";
                    result.desc = "类型不能为空";

                    isFlag = false;
                }

                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                if (isFlag)
                {
                    
                    DataSet ds;
                    
                    if (param.type == "1")
                    {
                        MassageData Data;
                        ds = ATMMassageCS.QueryNoPageList(param.page_no, param.page_count, param.SaveOrTake);
                       result.MassageData.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                       if (ds != null)
                       {
                           
                           foreach (DataRow dr in ds.Tables[1].Rows)
                           {
                               Data = new MassageData();
                               Data.msg_id = dr["ID"].ToString();
                               Data.msg_Title = dr["Title"].ToString();
                               Data.msg_CreateTime = dr["CreateTime"].ToString();
                               Data.msg_EndTiem = dr["EndTime"].ToString();
                               Data.msg_SaveOrTake = dr["SavaOrTake"].ToString();
                               Data.msg_BranchID = dr["BranchID"].ToString();
                               Data.msg_BranchName = dr["BranchName"].ToString();
                               result.MassageData.list.Add(Data);
                           }
                       }
                    }
                    else
                    {
                        MassageData Data;
                        ds = ATMMassageCS.QueryPageList(param.page_no, param.page_count, param.SaveOrTake);
                        result.MassageData.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);

                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            Data = new MassageData();
                            Data.msgT_SaveID = dr["SaveID"].ToString();
                            Data.msgT_TakeID = dr["TakeID"].ToString();
                            Data.msgT_Title = dr["Title"].ToString();
                            //Data.msgT_MatchID = dr["MatchID"].ToString();
                            Data.msgT_MatchTime = dr["MatchTime"].ToString();
                            //Data.msgT_SaveOrTake = dr["SavaOrTake"].ToString();
                            //Data.msgT_SaveBranchID = dr["BranchID"].ToString();
                            //Data.msgT_TakeBranchID = dr["BranchID"].ToString();
                            result.MassageData.list.Add(Data);
                        }
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetATMMassageList", SerializeHelper.JsonSerializer<GetATMMassageListInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<GetATMMassageListInParam, GetATMMassageListOutParam>();
            else
                SafeProcessRequest<GetATMMassageListInParam, GetATMMassageListOutParam>();
        }
    }

    #region 请求参数
    public class GetATMMassageListInParam
    {
        /// <summary>
        /// 类型   1:未匹配信息   2:已配对信息
        /// </summary>
        public string type
        { get; set; }

        /// <summary>
        /// 求助/捐助类型	string	Save:捐助 Take:求助
        /// </summary>
        public string SaveOrTake
        { get; set; }

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion


    #region 结果参数
    public class GetATMMassageListOutParam
    {
        public GetATMMassageListOutParam()
        {
            code = "1";
            desc = "操作成功";
            MassageData = new MassageDataList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public MassageDataList MassageData
        { get; set; }
    }

    public class MassageDataList
    {
        public MassageDataList()
        {
            total_pages = 0;
            list = new List<MassageData>();
        }

        public List<MassageData> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class MassageData
    {
        /// <summary>
        /// ID
        /// </summary>
        public string msg_id
        { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string msg_Title
        { get; set; }

        /// <summary>
        /// 捐助开始时间
        /// </summary>
        public string msg_CreateTime
        { get; set; }

        /// <summary>
        /// 结束时间（有效期）
        /// </summary>
        public string msg_EndTiem
        { get; set; }

        /// <summary>
        /// 捐助OR求助
        /// </summary>
        public string msg_SaveOrTake
        { get; set; }

        /// <summary>
        /// 组织ID
        /// </summary>
        public string msg_BranchID
        { get; set; }

        /// <summary>
        /// 组织名称
        /// </summary>
        public string msg_BranchName
        { get; set; }


        /// <summary>
        /// 捐助ID
        /// </summary>
        public string msgT_SaveID
        { get; set; }

        /// <summary>
        /// 求助ID
        /// </summary>
        public string msgT_TakeID
        { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string msgT_Title
        { get; set; }

        /// <summary>
        /// 匹配时间
        /// </summary>
        public string msgT_MatchTime
        { get; set; }

    }
    #endregion
}